class Node:
	def __init__(self, data=None, next=None):
		self.data = data
		self.next = next
	def __str__(self):
		return str(self.data)
	
class PQueue:
	def __init__(self):
		self.head = None
	def __str__(self):
		result = ""
		if self.is_empty():
			return result
		else:
			tmp = self.head
			while tmp:
				result += str(tmp.data)
				tmp = tmp.next
			
			return result
	def is_empty(self):
		return not self.head
	def insert(self, data):
		node = Node(data)
		before = None
		after = self.head
		while after:
			if after.data[1] > node.data[1]: break
			before = after
			after = after.next
		if before is None:
			node.next = self.head
			self.head = node
		else:
			node.next = before.next
			before.next = node
	def remove(self):
		data = self.head.data
		self.head = self.head.next
		return data